﻿using System.Windows;
using System.Windows.Controls.Primitives;
using XmlStudio.Settings;
using Tomers.WPF.Localization;
using System.Globalization;

namespace XmlStudio.Dialogs {
    /// <summary>
    /// Interaction logic for Settings.xaml
    /// </summary>
    // ReSharper disable RedundantExtendsListEntry
    public partial class SettingsDialog : Window {
        // ReSharper restore RedundantExtendsListEntry
        public SettingsDialog() {
            InitializeComponent();
        }

        protected virtual void OKClicked(object sender, RoutedEventArgs e) {
            var expression = DefaultLayoutAlgorithmComboBox.GetBindingExpression(Selector.SelectedValueProperty);
            if(expression != null)
                expression.UpdateSource();

            XmlStudioSettings.Instance.VertexDefaultFillBrush = ForeColorPicker.CurrentColor;
            XmlStudioSettings.Instance.VertexDefaultStrokeBrush = StrokeColorPicker.CurrentColor;
            XmlStudioSettings.Instance.HighlightedVertexBackgroundBrush = HighlightedVertexBackgroundBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.HighlightedVertexBorderBrush = HighlightedVertexBorderBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.HighlightedVertexForegroundBrush = HighlightedVertexForegroundBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SelectedVertexBackgroundBrush = SelectedVertexBackgroundBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SemiHighlightedSourceVertexBorderBrush = SemiHighlightedSourceVertexBorderBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SemiHighlightedSourceVertexBackgroundBrush = SemiHighlightedSourceVertexBackgroundBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SemiHighlightedTargetVertexBorderBrush = SemiHighlightedTargetVertexBorderBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SemiHighlightedTargetVertexBackgroundBrush = SemiHighlightedTargetVertexBackgroundBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.HighlightedEdgeBrush = HighlightedEdgeBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SemiHighlightedInEdgeBrush = SemiHighlightedInEdgeBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.SemiHighlightedOutEdgeBrush = SemiHighlightedOutEdgeBrushColorPicker.CurrentColor;
            XmlStudioSettings.Instance.Language = (LanguageSetting)LanguagesComboBox.SelectedValue;
            LanguageContext.Instance.Culture = CultureInfo.GetCultureInfo(XmlStudioSettings.Instance.Language.Value);
            XmlStudioSettings.Instance.NodeCountToExpand = int.Parse(NumberOfChildrenTextBox.Text);

            this.DialogResult = true;
            this.Close();
        }
    }
}